package me.mcx.mcx.web.controller;

import me.mcx.common.core.controller.BaseController;
import me.mcx.common.core.domain.AjaxResult;
import me.mcx.mcx.domain.McxWebConfig;
import me.mcx.mcx.service.IMcxWebConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 网站配置Controller
 * 
 * @author mcx
 * @date 2024-09-21
 */
@RestController
@RequestMapping("/api/mcx/webConfig")
public class ApiMcxWebConfigController extends BaseController
{
    @Autowired
    private IMcxWebConfigService mcxWebConfigService;

    /**
     * 查询网站配置列表
     */
    @GetMapping("/list")
    public AjaxResult list(McxWebConfig mcxWebConfig)
    {
        List<McxWebConfig> list = mcxWebConfigService.selectMcxWebConfigList(mcxWebConfig);
        return success(list);
    }

    /**
     * 获取网站配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mcxWebConfigService.selectMcxWebConfigById(id));
    }

    /**
     * 通过标题获取网站配置详细信息
     */
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo(@RequestParam String titles)
    {
        List<String> titleList = Arrays.stream(titles.split(","))
                .map(String::toString)
                .collect(Collectors.toList());
        return success(mcxWebConfigService.selectMcxWebConfigDict(titleList));
    }
}
